
{include file="public/top" /}

<body class="layui-anim layui-anim-up">

<div class="x-body">
    <div class="layui-row clear pagesa">
        <p class="fl">>评论列表</p>
    </div>
    <div class="layui-row" style="margin: 10px 0 -10px 0">

    </div>
    <table class="" lay-filter="test" id="table" >
    </table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit1">审核</a>
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">回复</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <input type="hidden" value="{$id}" id="id">
</div>
<script>
    //接口地址
    //获取列表接口
    var id = $('#id').val();
    var listurl = '/admin/Blog/getmessage/id/'+id;
    //删除接口
    var delurl = '/admin/Blog/messageDell';
    //审核接口
    var shenhe = '/admin/Blog/shenhe';
    layui.use('table', function(){
        var table = layui.table;
        //初始化表格
        table.render({
            elem: '#table'
            ,height: 'full-140'
            ,url: listurl //数据接口
            ,page: true //开启分页
            ,limit:20
            ,limits:[20,100,300]
            ,id:'idTest'
            ,cols: [[ //表头
                {field: 'id',width:40,title: 'ID', fixed: 'left'}
                ,{field: 'name', title: '名称'}
                ,{field: 'email', title: '邮箱'}
                ,{field: 'content', title: '评论内容'}
                ,{field: 'status', title: '审核状态'}
                ,{field: 'create_time', title: '创建时间'}
                ,{fixed: 'right',width:150, align:'center', toolbar: '#barDemo'}
            ]]
        });
        //监听表格复选框选择
        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //监听删除
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: delurl,
                        data: {'id':data.id},
                        success: function (res) {
                            var success = JSON.parse(res);
                            if(success.code===200){
                                layer.msg(success.msg);
                                obj.del();
                                layer.close(index);
                            }else {
                                layer.msg(success.msg)
                            }

                        }
                    });

                });
            }
            if(obj.event === 'edit1'){
                layer.confirm('是否通过审核？', function(index){
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: shenhe,
                        data: {'id':data.id},
                        success: function (res) {
                            var success = JSON.parse(res);
                            if(success.code===200){
                                obj.update({
                                    status: '已通过',
                                });
                                layer.msg(success.msg);
                            }else {
                                layer.msg(success.msg)
                            }

                        }
                    });

                });
            }
            if(obj.event === 'edit'){
                window.location.href = "/admin/blog/huifu?id="+data.id;
            }
        });


    });




</script>

</body>

</html>
